#!/usr/bin/perl -w

##HACKABOT_HELP##
# Who is asleep? 
# !sleep [#chan] [someone]
##HACKABOT_HELP##

use strict;
use DBI;
use Time::localtime;
use XML::Simple;

my $privmsg = 0;
my ($chan, $nick, $to, $msg);
while (<>) {
	if (/^type\s+privmsg/) {
		$privmsg = 1;
	}
	elsif (/^to\s+(\S+)/) {
		$chan = $1;
	}
	elsif (/^nick\s+(\S+)/) {
		$nick = $1;
	}
	elsif (/^msg\s+(#\S+)\s+(\S.*)/) {
		$to = $1;
		$msg = $2;
	}
	elsif (/^msg\s+(\S.*)/) {
		$msg = $1;
	}
}

if ($privmsg and not defined $to) {
	print "send zzzzzzz\n";
	exit;
}

if (defined $chan and defined $nick) {
	if (defined $to) {
		print "to $to\n";
	}
	if (not defined $msg) {
		$msg = $nick;
	}
	print "send you may be asleep but $msg is not.\n";
}

